#include <iostream>  
#include <algorithm>  
using namespace std;  
void swap(double &a, double &b) {  
    double temp = a;  
    a = b;  
    b = temp;  
}   
double sortArray(double *parray, int flag) {  
      
    for (int i = 0; i < 9; i++) {  
        for (int j = 0; j < 8-i; j++) {  
            if (flag == 0 && parray[j] > parray[j + 1]) {  
                swap(parray[j], parray[j + 1]);  
            } else if (flag == 1 && parray[j] < parray[j + 1]) {  
                swap(parray[j], parray[j + 1]);  
            }  
        }  
    }  
    return *parray;  
}  
  
int main() {  
    double arr[9];
    int n=9;
  
    std::cout << "请输入数组元素：";  
    for (int i = 0; i < n; i++) {  
        std::cin >> arr[i] ;   
    }  
    std::cout << std::endl;  
    std::cout << "*该数组从小到大排序结果：";  
    sortArray(arr, 0);  
    for (int i = 0; i < n; i++) {  
        std::cout << arr[i] << " ";  
    }  
    std::cout << std::endl;  
  
    std::cout << "*该数组从大到小排序结果：";  
    sortArray(arr, 1);  
    for (int i = 0; i < n; i++) {  
        std::cout << arr[i] << " ";  
    }  
    std::cout << std::endl;  
  
    return 0;  
}